package data;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import fileProcessing.ParsingException;

public class PhoneNumberEntry extends AbstractDataType<PhoneNumberEntry>{
	
	private String phoneNumber;
	private String fieldType = "Phone Number";
	
	public PhoneNumberEntry(){};
	
	public PhoneNumberEntry(String phoneNum) throws ParsingException{
		if(isValid(phoneNum))
			phoneNumber = phoneNum;
		else
			throw new ParsingException("Phone number not valid.");
	}
	
	public boolean isValid(String val){
		Pattern pattern = Pattern.compile("(1-\\d{3}-\\d{3}-\\d{4})|(\\d{3}-\\d{3}-\\d{4})|" +
				"(1//d{10})|(\\(\\d{3}\\)\\d{7})|(\\(\\d{3}\\)\\s?\\d{3}[\\s-]?\\d{4})", Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(val);
		return matcher.matches();
	}

	@Override
	public int compareTo(PhoneNumberEntry o) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType() {
		return fieldType;
	}

}
